import {Injectable} from "@angular/core";
import {Http,Headers} from "@angular/http";
import { Observable } from 'rxjs/Rx';
import {APP_CODE} from "../../app/common/app.config";
/**
 * Created by Yue on 2017/6/14.
 */
@Injectable()
export class RobotHttp{
  private robotUrl = 'http://jisuznwd.market.alicloudapi.com/iqa/query?question=';
  private headers = new Headers({'Authorization': 'APPCODE '+ APP_CODE});//APPCODE之后跟随空格

  constructor(private http: Http){
  }
  pushMessTo(message: string){
    let url = this.robotUrl+message;
    return this.http.get(url,{headers: this.headers})
      .map((response)=> response.json()) // 加map请求好慢好慢好慢。？？？？
      .catch((e)=>{
        return Observable.throw(
          new Error(`${ e.status } ${ e.statusText }`)
        );
      });

  }
}
